/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pio.action.coordinador;

import DBMS.DataBaseManager;
import clases.Coordinador;
import clases.Institucion;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

/**
 *
 * @author tamerdark
 */
public class ModificarMisDatos extends DispatchAction {

    public ActionForward update(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        Coordinador c = (Coordinador) form;
        System.out.println("La nacionalidad es:" + c.getNacionalidad());
        DataBaseManager dbms = DataBaseManager.getInstance();
        boolean modificado = dbms.modificarCoordinador(c);
        if (modificado) {
            c.setMensaje("Datos actualizados correctamente");
            return mapping.findForward("success");
        } else {
            c.setMensaje("Error actualizando datos.");
            return mapping.findForward("failure");
        }
    }

    public ActionForward populate(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        Coordinador c = (Coordinador) form;
        c.setCedula(String.valueOf(request.getSession().getAttribute("cedula")));
        System.out.println("1)mi cedula es:" + c.getCedula());
        DataBaseManager dbms = DataBaseManager.getInstance();
        List l = dbms.consultarCoordinador(c);
        if (l.isEmpty()) {
            c.setMensaje("Error cargando sus datos de la base de datos.");
            return mapping.findForward("failure");
        } else {
            c.cloneWith((Coordinador) l.get(0));
            System.out.println("2)mi nombre es:" + c.getCedula());
            return mapping.findForward("success");
        }
    }
}
